<template>
  <div class="top_operation_bar_box">
    <div class="top_operation_bar_img">
      <img src="https://y.qq.com/mediastyle/mod/mobile/img/logo.svg" />
    </div>
    <div class="top_operation_bar_bd">
      <h2 class="top_operation_bar_tit">QQ音乐</h2>
      <p class="top_operation_bar_txt">打开APP收藏下载</p>
    </div>
    <div class="top_operation_bar_btn">
      <a href="#" class="top_operation_bar_btn">下载APP</a>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      screenWidth: document.body.clientWidth // 屏幕宽
    };
  },
  mounted() {
    const that = this;
    window.onresize = () => {
      return (() => {
        window.screenWidth = document.body.clientWidth;
        that.screenWidth = window.screenWidth;
      })();
    };
  },
  watch: {
    screenWidth(val) {
      // 为了避免频繁触发resize函数导致页面卡顿，使用定时器
      if (!this.timer) {
        // 一旦监听到的screenWidth值改变，就将其重新赋给data里的screenWidth
        this.screenWidth = val;
        this.timer = true;
        let that = this;
        setTimeout(function() {
          // 打印screenWidth变化的值
          // console.log(that.screenWidth);
          that.timer = false;
        }, 400);
      }
    }
  }
};
</script>

<style scoped>
.top_operation_bar_box {
  box-sizing: border-box;
  background-color: #fafafa;
  position: fixed;
  width: 100%;
  height: 60px;
  padding: 0 15px;
  font-size: 10px;
  z-index: 999;
  box-shadow: 0 3px 25px rgb(0 0 0 / 5%);
}
.top_operation_bar_img {
  border-radius: 0.5em;
  background-color: #fff;
  width: 40px;
  height: 40px;
  line-height: 40px;
  margin: 10px 0;
  float: left;
}
.top_operation_bar_img img {
  height: 30px;
  border-radius: 0;
  vertical-align: middle;
}
.top_operation_bar_bd {
  box-sizing: border-box;
  /* width: 70%; */
  height: 60px;
  float: left;
  padding-left: 1em;
}
.top_operation_bar_tit {
  font-size: 18px;
  color: #000;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  margin: 0;
  position: relative;
  top: 7px;
  text-align: left;
  font-weight: normal;
}
.top_operation_bar_txt {
  font-size: 13px;
  color: grey;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  margin: 0;
  position: relative;
  top: 6px;
  float: left;
}
.top_operation_bar_btn {
  width: 20%;
  min-width: 60px;
  max-width: 100px;
  float: right;
}
.top_operation_bar_btn a {
  width: 100%;
  height: 30px;
  line-height: 30px;
  margin: 15px 0;
  color: #575656;
  border: solid 1px #d8d8d8;
  border-radius: 999px;
  box-sizing: border-box;
  font-size: 0.6rem;
}
@media(max-width:319px){
  .top_operation_bar_tit{
    font-size: 16px;
  }
  .top_operation_bar_txt{
    font-size: 12px;
  }
}
</style>
